/**
 * 
 * @author Ivam Henrique Marques dos Santos
 *         email: ivam.santos@skytef.com.br
 *         skype: ivam.santos.skytef
 *         telefone: +55 11 96214-7543
 */

package br.skytef.stmanager.beans;

import java.io.IOException;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import org.eclipse.persistence.exceptions.SessionLoaderException;
import org.primefaces.context.RequestContext;

import br.skytef.stmanager.entities.UsuarioEntity;

/** 
 * Class Controller DashboardController
 */
@ManagedBean(name="DashboardBean")
@RequestScoped
public class DashboardBean {
	
	/**
	 * Campos e seus respectivos Getters e Setters.
	 */
	
	static RequestContext context;
	
	public UsuarioEntity getUsuario() {return usuario;}
	public void setUsuario(UsuarioEntity usuario) {DashboardBean.usuario = usuario;}
	private static UsuarioEntity usuario ;
	
	public String getCurrentMenu() {return currentMenu;}
	public void setCurrentMenu(String currentMenu) {this.currentMenu = currentMenu;}
	private String currentMenu = "menu.xhtml";  
	
	private String currentRodape = "rodape.xhtml";
	public String getCurrentRodape() {return currentRodape;}
	public void setCurrentRodape(String currentRodape) {this.currentRodape = currentRodape;}
	
	private static String rodape;
	public static String getRodape() {return rodape;}
	public static void setRodape(String rodape) {DashboardBean.rodape = rodape;}
	
	private HttpSession session;
	
	/**
	 * Construtor
	 * @throws IOException
	 */
	public DashboardBean() throws IOException {
		super();
		try {
			FacesContext ctx = FacesContext.getCurrentInstance();
			session = (HttpSession) ctx.getExternalContext().getSession(false);
			usuario = (UsuarioEntity)session.getAttribute("usuario");
			if(usuario == null){
				new LoginBean().encerraSessao();
			}
		}catch(SessionLoaderException e){ 
			new LoginBean().encerraSessao();
		}
	}
	/**
	 * Métodos para navegação entre páginas
	 * @throws IOException
	 */
	public static void pageHome() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("dashboard.xhtml"); 
	}
	
	public static void pageUsuario() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("usuario.xhtml"); 
	}
	public static void pageImportacao() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("importacao.xhtml");
	}
	public static void pageExibirPlan() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("exibirplan.xhtml");
	}
	public static void pageConsultarCliente() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("consultarCliente.xhtml");
	}
	
	public static void pageCadastrarCliente() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("cadastrarCliente.xhtml");
	}
	
	public static void pageCadastrarUsuario() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("cadastrarUsuario.xhtml");
	}
	
	public static void pagenovaTarefa() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("tarefa.xhtml");
	}
	
	public static void pageGeral() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("relatorioGerencial.xhtml");
	}
	
	public static void pageImportarVPN() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("relatorioImpVPN.xhtml");
	}
	
	public static void pageUsuarioEditar() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("editarUsuario.xhtml");
	}
	
	public static void pageProtocolo() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("protocolo.xhtml"); 
	}
	
	public static void pageProtocoloReabertura() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("protocoloReabertura.xhtml"); 
	}
	
	public static void pageconsultarTarefa() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("consultarTarefa.xhtml"); 
	}
	
	public static void  pageHistoricoTarefa() throws IOException{
		context = RequestContext.getCurrentInstance(); 
		FacesContext.getCurrentInstance().getExternalContext()  
		.redirect("historicoTarefa.xhtml"); 
	}

	
	/**
	 * Método Logout
	 * @throws IOException
	 */
	public void logout() throws IOException{
		new LoginBean().encerraSessao();
	}
	
}
